<?php
/**
 * Created by PhpStorm.
 * User: HLG
 * Date: 2019/10/16
 * Time: 14:01
 */
namespace app\api\model;
use app\common\model\UploadFile;
use think\Request;
use think\Db;
class OrderAddress extends BaseModel
{
    protected $table = 'yoshop_order_address';

    /**
     * 添加订单收货地址
     *
     * @param $address_id
     * @param $user_id
     * @param $order_id
     * @return bool|int|string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function addOrderAddress($address_id,$user_id,$order_id)
    {
        //查询地址详情
        $addressModel = new Address();
        $addressRes = $addressModel->getAddressInfo($user_id,$address_id);
        if($addressRes['code']==1){
            $addressInfo = $addressRes['data'];
            $insertData = [
                'name' => $addressInfo['name'],
                'phone' => $addressInfo['phone'],
                'province_id' => $addressInfo['province_id'],
                'city_id' => $addressInfo['city_id'],
                'region_id' => $addressInfo['region_id'],
                'detail' => $addressInfo['detail'],
                'order_id' => $order_id,
                'user_id' =>$user_id,
                'wxapp_id' => '10001',
                'create_time' => time(),
            ];
            $insertOrder = $this->allowField(true)->insertGetId($insertData);
            return $insertOrder;
        }else{
            return false;
        }

    }
}